﻿using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Hosting;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;

namespace FriendFunny.Tool.GlobalApp
{
    public static class HostServer
    {
        public static IHost Initialization(string[] args)
        {
            var builder = Host.CreateDefaultBuilder(args);

            builder = builder.ConfigureWebHostDefaults(webHostBuilder =>
            {
                var defaultAssemblyName = Assembly.GetAssembly(typeof(GlobalAppExtensions))?.GetName().Name;
                var environmentVariables = Environment.GetEnvironmentVariable("ASPNETCORE_HOSTINGSTARTUPASSEMBLIES");
                var combineAssembliesName = $"{defaultAssemblyName};{environmentVariables}";
                webHostBuilder.UseSetting(WebHostDefaults.HostingStartupAssembliesKey, combineAssembliesName);
            });

            var app = builder.Build();
            return app;
        }
    }
}
